﻿using System.Text;

namespace ShareHelper
{
    /// <summary>
    /// 字符串助手类
    /// </summary>
    public static class StringHelper
    {
        /// <summary>字符串转数组</summary>
        /// <param name="value">字符串</param>
        /// <param name="encoding">编码，默认utf-8无BOM</param>
        /// <returns></returns>

        public static byte[] GetBytes(this string value, Encoding encoding = null)
        {
            if (string.IsNullOrEmpty(value)) return new byte[0];
            if (encoding == null) encoding = Encoding.UTF8;
            return encoding.GetBytes(value);
        }
    }
}